import cv2
import os
import glob
import numpy as np
from math import*
import imutils

def rotate_img(img,angle):
    h,w = img.shape[:2]
    rotate_center = (w/2,h/2)
    M = cv2.getRotationMatrix2D(rotate_center,angle,1.0)
    new_w = int(h*np.abs(M[0,1])+w*np.abs(M[0,0]))
    new_h = int (h * np.abs(M[0,0]) + w * np.abs(M[0,1]))

    M[0,2] += (new_w - w) / 2
    M[1,2] += (new_h - h) / 2
    rotate_img = cv2.warpAffine(img,M,(new_w,new_h))
    return rotate_img
n =120

if __name__ == '__main__':
    output_dir = 'train-red'
    image_names = glob.glob('red2.jpg')
    for image_name in image_names:
        image = cv2.imread(image_name,-1)

        for i in range(1,360,3):
            n +=1
            rotate_img1 = rotate_img(image,i)
            basename = os.path.basename(image_name)
            tag,_ = os.path.splitext(basename)
            cv2.imwrite(os.path.join(output_dir,'red-1-%d.jpg'%n),rotate_img1)
